from concurrent.futures import ThreadPoolExecutor

import requests
from DrissionPage._base.chromium import Chromium
from DrissionPage._configs.chromium_options import ChromiumOptions


co = ChromiumOptions()
# co = ChromiumOptions().headless()
# co.set_browser_path(r'/opt/google/chrome/google-chrome')
# co.set_argument('--no-sandbox')
# 设置启动时最大化
co.set_argument('--start-maximized')
# 无痕
# co.set_argument('--incognito')
# 连接浏览器
browser = Chromium(co)

tab = browser.latest_tab

tab.get('https://jncc.jinan.gov.cn/jnfdcinfo/jnfdcweb/onsaling/viewhouse.shtml?fmid=60deff0f-0bfc-4ba1-ad11-f1b0d69f50e8')

td_list = tab.ele('#floorTable').s_eles('@tag()=td')
# print(id_list)
def get_house_info(id):
    data = requests.get(f'https://jncc.jinan.gov.cn/jnfdcinfo/jnfdcweb/onsaling/viewDiv.shtml?fid={id}').json()
    print(data)
# for td in td_list:
#     id = td.attr('id')
#     if id:
#         data = requests.get(f'https://jncc.jinan.gov.cn/jnfdcinfo/jnfdcweb/onsaling/viewDiv.shtml?fid={id}').json()
#         print(data)
with ThreadPoolExecutor(max_workers=20) as executor:
    for td in td_list:
        id = td.attr('id')
        if id:
            executor.submit(get_house_info, id)